package com.ly.common.core.bean.vo;

import cn.hutool.core.util.ObjUtil;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 树-vo
 *
 * @author jeecg
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class TreeVO implements Serializable {

    private static final long serialVersionUID = 4013193970046502756L;

    /**
     * key
     */
    private String key;

    /**
     * 标题
     */
    private String title;

    /**
     * 上级key
     */
    private String parentKey;

    /**
     * 是否禁用
     */
    private Boolean disabled = false;

    /**
     * 叶子节点(设置了loadData时有效)
     */
    private Boolean isLeaf = false;

    /**
     * 图标
     */
    private String icon;

    private String slotTitle;

    private Integer ruleFlag;

    private Map<String, String> scopedSlots;

    private String label;

    private String value;

    /**
     * 扩展数据
     */
    private Object ext;
    private List<TreeVO> children = new ArrayList<>();

    public TreeVO(String key, String title, String parentKey) {
        this.key = key;
        this.title = title;
        this.value = key;
        this.label = title;
        this.parentKey = parentKey;
        this.isLeaf = true;
    }

    /**
     * 基础表
     *
     * @param key
     * @param title
     * @param ext
     */
    public TreeVO(String key, String title, String parentKey, Object ext) {
        this.key = key;
        this.title = title;
        this.value = key;
        this.label = title;
        this.ext = ext;
        this.parentKey = parentKey;
    }

    /**
     * 一般封装
     *
     * @param key
     * @param parentKey
     * @param title
     * @param isLeaf
     */
    public TreeVO(String key, String title, String parentKey, Boolean isLeaf) {
        this.key = key;
        this.title = title;
        this.parentKey = parentKey;
        this.value = key;
        this.label = title;
        this.isLeaf = ObjUtil.equals(isLeaf,true);
    }

    public TreeVO(String key, String parentKey, String slotTitle, Integer ruleFlag, Boolean isLeaf) {
        this.key = key;
        this.parentKey = parentKey;
        this.ruleFlag = ruleFlag;
        this.slotTitle = slotTitle;
        this.scopedSlots = new HashMap<>() {{
            put("title", "hasDatarule");
        }};
        this.isLeaf = isLeaf;
        this.value = key;
    }
}
